import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { Provider } from "react-redux";
import store from "./app/store";
import { worker } from './api/server'
//import { fetchUsers } from './features/users/usersSlice'
//import apiSlice  from "./features/api/apiSlice";
import { extendedApiSlice } from './features/users/usersSlice' 
console.log('extendedApiSlice',extendedApiSlice)

// const root = ReactDOM.createRoot(document.getElementById('root'));
// root.render(
//     <Provider store={store}>
//       <App />
//     </Provider>
// );


async function start() {
  // Start our mock API server
  await worker.start({ onUnhandledRequest: 'bypass' })

  // let promise = store.dispatch(apiSlice.endpoints.getUsers.initiate());
  let promise = store.dispatch(extendedApiSlice.endpoints.getUsers.initiate());

  promise
  .unwrap() // 解包结果：成功返回 data，失败抛出 error
  .then(data => console.log('用户数据:', data))
  .catch(error => console.error('获取用户失败:', error));

  //store.dispatch(fetchUsers())

  const root = ReactDOM.createRoot(document.getElementById('root'))

  root.render(
      <Provider store={store}>
        <App />
      </Provider>
  )
}

start()

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
